package health.lm.com.find.adapter;

import android.support.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import health.lm.com.component_base.helper.ImageLoaderHelper;
import health.lm.com.find.R;
import health.lm.com.find.entity.HActivityItemEntity;

/**
 * 链活动
 * @author Administrator
 */

public class HActivityItemAdapter extends BaseQuickAdapter<HActivityItemEntity.Lists,BaseViewHolder> {
    public HActivityItemAdapter(@Nullable List<HActivityItemEntity.Lists> data) {
        super(R.layout.item_h_activity, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HActivityItemEntity.Lists item) {
        helper.setText(R.id.tv_title,item.getTitle())
                .setText(R.id.tv_date,getDate2String(item.getBegintime(),"yyyy年MM月dd日")+"-"+getDate2String(item.getEndtime(),"yyyy年MM月dd日"))
                .setText(R.id.tv_adr1,item.getAddress());
        if (StringUtils.isEmpty(item.getBackground())){
            ImageLoaderHelper.getInstance().load(mContext,getBg(helper.getLayoutPosition()),helper.getView(R.id.iv_background));
        }else {
            ImageLoaderHelper.getInstance().load(mContext,item.getBackground(),helper.getView(R.id.iv_background));
        }
    }
    private int getBg(int pos){
        int i = R.drawable.profile_activity_image_01;
        if(pos%3 == 1){
            i = R.drawable.profile_activity_image_02;
        }else  if(pos%3 == 2){
            i = R.drawable.profile_activity_image_03;
        }
        return i;
    }
    /**
     *
     * @param time  1541569323155
     * @param pattern yyyy-MM-dd HH:mm:ss
     * @return 2018-11-07 13:42:03
     */
    public static String getDate2String(long time, String pattern) {
        Date date = new Date(time*1000L);
        SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault());
        return format.format(date);
    }
}
